while True:
    try:
        num1 = int(input("请输入第一个数字: "))
        break
    except ValueError:
        print("错误：输入的不是有效的数字，请重新输入。")

while True:
    operator = input("请输入运算符（+，-，*，/，=，q 退出）: ")
    if operator == 'q':
        break
    try:
        num2 = int(input("请输入下一个数字: "))
        if operator == '+':
            result = num1 + num2
        elif operator == '-':
            result = num1 - num2
        elif operator == '*':
            result = num1 * num2
        elif operator == '/':
            if num2 == 0:
                print("错误：除数不能为零，请重新输入。")
                continue
            result = num1 / num2
        elif operator == '=':
            print(num1)
            break
        else:
            print("错误：无效的运算符，请重新输入。")
            continue
        num1 = result
    except ValueError:
        print("错误：输入的不是有效的数字，请重新输入。")

